package site.jlopen.secret.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.hutool.core.lang.TypeReference;
import site.jlopen.secret.client.SecretReqUrl;
import site.jlopen.secret.client.SecretClientHttp;
import site.jlopen.secret.common.SecretClientResponse;
import site.jlopen.secret.common.SecretReqBaseForm;
import site.jlopen.secret.config.SecretClientProperties;
import site.jlopen.secret.model.result.SecretResultResp;
import site.jlopen.secret.service.intf.SecretResultManage;

public class SecretResultImpl implements SecretResultManage {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	private final SecretClientProperties clientProperties;
	
	public SecretResultImpl(SecretClientProperties clientProperties) {
		this.clientProperties = clientProperties;
	}

	@Override
	public SecretClientResponse<SecretResultResp> resultInfo(String resultId) {
		logger.info("查询{}结果信息", resultId);
		SecretClientHttp<SecretResultResp> clientRequest = new SecretClientHttp<SecretResultResp>(clientProperties);
		Map<String, Object> form = new SecretReqBaseForm<Object>().add("resultId", resultId)
				.appId(clientProperties.getAppId());
		SecretClientResponse<SecretResultResp>  res = clientRequest.execute(SecretReqUrl.RESULT_INFO_URL, form, new TypeReference<SecretClientResponse<SecretResultResp>>() {});
		return res;
	}

	@Override
	public SecretClientResponse<List<SecretResultResp>> resultList() {
		logger.info("查询所有结果列表信息");
		SecretClientHttp<List<SecretResultResp>> clientRequest = new SecretClientHttp<List<SecretResultResp>>(clientProperties);
		Map<String, Object> form = new SecretReqBaseForm<Object>()
				.appId(clientProperties.getAppId());
		SecretClientResponse<List<SecretResultResp>>  res = clientRequest.execute(SecretReqUrl.RESULT_LIST_URL, form, new TypeReference<SecretClientResponse<List<SecretResultResp>>>() {});
		return res;
	}

}
